import 'dart:async';
import 'package:get/get.dart';

class TimerController extends GetxController {
  Timer? _timer;
  var seconds = 60.obs;
  void startTimer({Function()? callBack}) {
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
      if(seconds.value == 0){
        callBack?.call();
        stopTimer();
        seconds.value = 60;
        return;
      }
      seconds.value --;
    });
  }

  void stopTimer() {
    _timer?.cancel();
  }

  void resetTimer() {
    seconds.value = 0;
  }

  @override
  void onClose() {
    _timer?.cancel();
    super.onClose();
  }
}